from selenium.webdriver.common.by import By
from common.basepage import BasePage


class MarketingPage(BasePage):


    """营销页面"""
    # (By.XPATH, '')
    # 发券中心
    send_ticket_center_locator = (By.XPATH, '//*[@class="m-name" and text()="发券中心"]/../..')
    # 发券中心-立即使用
    sendTicket_immediateUse_locator = (By.XPATH, '//*[text()="发券中心"]/../following-sibling::div/button[1]')
    # 限时秒杀
    seckill_icon_locator = (By.XPATH, '//*[@class="m-name" and text()="限时秒杀"]/../..')
    # 限时秒杀-立即使用
    seckill_immediateUse_locator = (By.XPATH, '//*[text()="限时秒杀"]/../following-sibling::div/button[1]')
    # 继续使用按钮
    continueUsing_btn_locator = (By.XPATH, '//*[@aria-label="提示"]/div[3]//button[2]')
    # 节日礼券
    holiday_gift_locator = (By.XPATH, '//*[@class="m-name" and text()="节日礼券"]/../..')
    # 发券中心-立即使用
    holidayGift_immediateUse_locator = (By.XPATH, '//*[text()="节日礼券"]/../following-sibling::div/button[1]')


    """发券中心子页面元素"""
    # 新增活动按钮
    sendTicket_addBtn_locator = (By.CSS_SELECTOR, 'span.addNews1')
    # 查询活动输入框
    sendTicket_searchInput_locator = (By.CSS_SELECTOR, '*[placeholder="请输入内容"]')
    # 查询查询按钮
    sendTicket_searchBtn_locator = (By.CSS_SELECTOR, 'i.el-icon-search')
    # 查看按钮
    sendTicket_checkBtn_locator = (By.XPATH, '//*[@class="cont-tab"]/ul[2]/li[9]/span')

    """新增优惠券页面元素"""
    # 活动名称输入框
    sendTicket_nameInput_locator = (By.XPATH, '//input[@placeholder="请输入20字内名称"]')
    # 活动时间-开始选择框
    sendTicket_startBtn_locator = (By.XPATH, '//ul/li[7]//input[@placeholder="开始时间"]')
    # 活动时间-结束选择框
    sendTicket_endBtn_locator = (By.XPATH, '//ul/li[7]//input[@placeholder="结束时间"]')
    # 此刻按钮
    sendTicket_nowBtn_locator = (By.XPATH, '//*[contains(@x-placement,"start")]/div[2]/button[1]')
    # 面额输入框
    sendTicket_denoInput_locator = (By.XPATH, '//ul[2]/li[1]//input[@placeholder="请输入内容"]')

    def send_ticket_center(self):
        return self.visible_only_wait(self.send_ticket_center_locator)

    def immediateUse(self):
        return self.presence_only_wait(self.sendTicket_immediateUse_locator)



    def click_tt(self):
        self.driver.execute_script("arguments[0].click();", self.immediateUse())


    def click_immediateUse(self):
        ticket_center = self.send_ticket_center()
        immediateUse = self.immediateUse()
        self.mouseOver(ticket_center,immediateUse)